/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.jSkyRoom;

import ru.jSkyRoom.manager.ModManager;
import ru.jSkyRoom.CompositeMod;
import ru.jSkyRoom.manager.ModImporter;
import ru.jSkyRoom.support.SyntaticModBuilder;
import ru.jSkyRoom.manager.JSkyGlobal;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import ru.jSkyRoom.finder.FinderByEdidFacade;
import ru.jSkyRoom.factory.BridgeFactory;
import ru.jSkyRoom.factory.FinderByEdidFactory;
import ru.jSkyRoom.interfaces.JSkyMod;
import ru.jSkyRoom.support.GrupTypeBuilder;
import skyproc.GRUP_TYPE;
import skyproc.ModListing;
import skyproc.SPGlobal;
import skyproc.exceptions.BadMod;
import skyproc.exceptions.MissingMaster;

/**
 *
 * @author Rakev
 */
public class MatcherTestWithMods {

    private JSkyMod creatingMod;
    private FinderByEdidFacade finder;

    protected GRUP_TYPE[] getImportedGrupTypes() {
        GrupTypeBuilder typeBuilder = new GrupTypeBuilder();
        typeBuilder.All();
        return typeBuilder.build();
    }

    protected JSkyMod createMerger() {
        SyntaticModBuilder builder = new SyntaticModBuilder();
        builder.add("Skyrim.esm");
        return builder.build();
    }

    @BeforeMethod
    public void setUp() {
        initSettings();
        creatingMod = getBridgeFactory().createBridge(SPGlobal.getGlobalPatch());
        finder = FinderByEdidFacade.create();
    }

    private void initSettings() {
        try {
            String pathToData = "C:\\Steam\\SteamApps\\common\\skyrim\\Data\\";
            String importingMod = "Skyrim.esm";
            GRUP_TYPE[] grupTypes = getImportedGrupTypes();

            JSkyGlobal.getInstance().begin().selectActiveMode(pathToData).beginCreatingMod("Rakev", "Test").
                    importMod(importingMod, grupTypes);
        } catch (MissingMaster | BadMod ex) {
            ex.printStackTrace();
            RuntimeException newEx = new IllegalStateException("Init error");
            newEx.addSuppressed(ex);
            throw newEx;
        }
    }

    protected FinderByEdidFactory getFinderFactory() {
        return FinderByEdidFactory.create();
    }

    /**
     * @return the merger
     */
    protected JSkyMod getMerger() {
        return new CompositeMod(ModManager.getInstance().getModsWithoutActive());
    }

    /**
     * @return the bridgeFactory
     */
    protected BridgeFactory getBridgeFactory() {
        return BridgeFactory.create();
    }

    /**
     * @return the creatingMod
     */
    protected JSkyMod getCreatingMod() {
        return creatingMod;
    }

    public FinderByEdidFacade getFinderFacade() {
        return finder;
    }
}
